﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="CodeDemon.Views.Builder.Index" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

<% var repos = (from repoList in ViewData.Model.DAO.GetSVNRepositories() select repoList); %>

<form action="/CodeDemon/Builder/CreateReview" method="post" id="htmlForm">


    <h2>Create A New Code Review</h2>
    <div id="step1">
    <h3>Step 1: Review Details</h3>
    <div>
    <label for="Title"><span>Title:</span><input id="Title" name="Title" value="<%= ViewData.Model.VarHash["Title"] %>" /></label>
    </div>
    
    
    
    <div>
    <label for="Defect"><span>DefectID:</span><input name="DefectID" id="DefectID" value="<%= ViewData.Model.CurrentDefectNumber %>" /></label>
    </div>
    
    <div>
    <label for="RepositoryID"><span>Repository:</span></span><select name="RepositoryID">
        <% foreach (var repo in repos)
           { %>
            <option value="<%= repo.RepositoryID %>"><%= repo.RepositoryURL %></option>

         <%  } %>
    </select></label>
    </div>
    
    <div>
    <label for="Description"><span>Description:</span><textarea id="Description" name="Description" rows="10" cols="50" ></textarea></label>
    </div>
        <p>Enter the details for this review.</p>
        <input type="button" id="go_to_step2" value="&gt;&gt;&nbsp;Proceed To Step #2&nbsp;&gt;&gt;" />
    </div>
    
    <div id="step2" style="display:none;">
    <h3>Step 2: Review Users</h3>
    <table><tr><td>
    Reviewers:<p id="reviewerslist"><img src="/CodeDemon/Content/spinner.gif" alt="Loading" />Loading User List...<img src="/CodeDemon/Content/spinner.gif" alt="Loading" /></p></label>
   </td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>
    CC:<p id="cclist1"><img src="/CodeDemon/Content/spinner.gif" alt="Loading" />Loading User List...<img src="/CodeDemon/Content/spinner.gif" alt="Loading" /></p></label>
    </td></tr></table>
    <p>Select users to invite to this review as partipants and optionally auxillery users to invite.</p>
    <input type="button" id="go_to_step3" value="&gt;&gt;&nbsp;Proceed To Step #3&nbsp;&gt;&gt;" />
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
     var date = new Date();
        $.ajax({
                url: '/CodeDemon/User/DisplayUserList',
                data: 'multi=true&cssId=reviewers&noSelf=true',
                type: 'POST',
                dataType: 'html',
                timeout: 8000,
            error: function(){
                alert('Error loading the user menu.');
            },
            success: function(TheHtml){
                $('#reviewerslist').html(TheHtml).show('1');
            }
        });
        
        $.ajax({
                url: '/CodeDemon/User/DisplayUserList',
                data: 'multi=true&cssId=cclist&noSelf=true',
                type: 'POST',
                dataType: 'html',
                timeout: 8000,
            error: function(){
                alert('Error loading the user menu.');
            },
            success: function(TheHtml){
                $('#cclist1').html(TheHtml).show('1');
            }
        });
  
            
            $('#go_to_step2').click(function() { 
            
                if($('#DefectID').val() == 0 ) {
                    alert('You must supply a defect ID');
                    return false;
                }
                if($('#Title').val() == "" ) {
                    alert('You must supply a Review Title');
                    return false;
                }
                if($('#Description').val() == "" ) {
                    alert('You must supply a Review Description');
                    return false;
                }
                $('#step1').hide('1');
                $('#step3').hide('1');
                $('#step2').show('1');
                
            });
            $('#go_to_step3').click(function() { 
                if($('#reviewers').val() == undefined ) {
                    alert('You must select at least one reviewer');
                    return false;
                }
                $('#step1').hide('1');
                $('#step2').hide('1');
                $('#step3').show('1');
                var defectNumber = $('#DefectID').val();
            $.ajax ( {
                url: '/CodeDemon/Builder/DisplayRevisions',
                data: 'defectID=' + defectNumber + '&amp;time=' + date.getTime(),
                type: 'POST',
                dataType: 'html',
                timeout: 8000,
                error: function(){
                    alert('Error loading your diff');
                },
                success: function(TheHtml){
                    $('#CreateReviewDiv').html(TheHtml).show('1');
                    $('#FetchRevisions').hide();
                    }
                });
            
            });
        
    });
    </script>

    
    <div id="step3" style="display:none;">
    <h3>Step 3: Review Revisions</h3>
        <div id="CreateReviewDiv">
            <img src="/CodeDemon/Content/spinner.gif" alt="Loading" />Loading Revision Lists<img src="/CodeDemon/Content/spinner.gif" alt="Loading" />
        </div>
            <br /><br />
        </form>
    </div>
    
</asp:Content>
